﻿using CoachingOrganizer.iOS.Controllers.Tools.MoneyCalculation;
using CoachingOrganizer.Logic.Models.Tools.MoneyCalculation;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace CoachingOrganizer.iOS.DataSources.Tools.MoneyCalculation
{
    public class ReportPeriodSizesDataSource : UIPickerViewModel
    {
        private readonly UIPickerView _view;
        private readonly ResultsMoneyCalculationDetailsViewController _controller;
        private readonly MoneyCalculationModel _model;
        private readonly Dictionary<string, TimeSpan> _periodSizes;

        public ReportPeriodSizesDataSource(UIPickerView view, ResultsMoneyCalculationDetailsViewController controller, MoneyCalculationModel model)
        {
            _view = view;
            _controller = controller;
            _model = model;
            _periodSizes = GetPeriodSizes();
        }

        public override int GetRowsInComponent(UIPickerView picker, int component)
        {
            return _periodSizes.Count;
        }

        public override string GetTitle(UIPickerView picker, int row, int component)
        {
            return _periodSizes.Keys.ElementAt(row);
        }

        private Dictionary<string, TimeSpan> GetPeriodSizes()
        {
            string plistFilePath = NSBundle.MainBundle.PathForResource("PeriodSizes", "plist");
            using (NSDictionary dataDictionary = NSDictionary.FromFile(plistFilePath))
                return dataDictionary.ToDictionary(i => (string)(NSString)i.Key, i => TimeSpan.FromSeconds(double.Parse((NSString)i.Value, CultureInfo.InvariantCulture)));
        }
    }
}
